RAIS  3.2
C:/Projekte/RAIS/Rais32UpdateTool/MainForm.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.ComponentModel;
00004 using System.Data;
00005 using System.Data.OleDb;
00006 using System.Data.SqlClient;
00007 using System.Diagnostics;
00008 using System.Drawing;
00009 using System.IO;
00010 using System.Linq;
00011 using System.Text;
00012 using System.Windows.Forms;
00013 using System.Xml;
00014 using System.Threading; 
00015 using FillCustomQueryTableCL;
00016 
00017 namespace RAISInstall
00018 {
00019     public partial class MainForm : Form
00020     {
00021         private string sqlConnection;
00022         
00023         delegate void UpdateStatusDelegate(string text);
00024 
00025         public MainForm()
00026         {
00027             InitializeComponent();
00028 
00029                         // Set initial values
00030                         sqlServerTextBox.Text = @"localhost\SQLEXPRESS2008";
00031                         sqlCatalogTextBox.Text = "RAIS_32";
00032         }
00033 
00034         
00035         private void button3_Click(object sender, EventArgs e)
00036         {
00037                         tbStatus.Clear();
00038 
00039             string errorString="";
00040             //if ((passTextBox.Text == "") && (!cbIntegratedSecurity.Checked))
00041             //    errorString = "Enter User password";
00042             //if ((loginTextBox.Text == "") && (!cbIntegratedSecurity.Checked))
00043             //    errorString = "Enter User login";
00044             if (sqlCatalogTextBox.Text == "")
00045                 errorString = "Enter SQL Server catalog";
00046                         if (sqlServerTextBox.Text == "")
00047                                 errorString = "Enter SQL Server name";
00048                         
00049                         if (errorString == "")
00050             {
00051                 string sqlConnectionFormat = "Data Source={0};Initial Catalog={1};Integrated Security=True;";
00052                 //string sqlConnectionFormat;
00053                 //if (cbIntegratedSecurity.Checked)
00054                 //{
00055                     //sqlConnectionFormat = "Data Source={0};Initial Catalog={1};Integrated Security=True;";
00056                     sqlConnection = string.Format(sqlConnectionFormat, sqlServerTextBox.Text, sqlCatalogTextBox.Text);
00057                 //}
00058                 //else
00059                 //{
00060                 //    sqlConnectionFormat = "Data Source={0};Initial Catalog={1};Integrated Security=False;User ID={2};Password={3};";
00061                 //    sqlConnection = string.Format(sqlConnectionFormat, sqlServerTextBox.Text, sqlCatalogTextBox.Text, loginTextBox.Text, passTextBox.Text);
00062                 //}
00063                 // accessConnection = string.Format(accessConnectionFormat, mdbFileName.Text, mdwFileName.Text, creatorLoginTextbox.Text, creatorPassTextbox.Text);
00064                 tbStatus.Focus();
00065                 Thread migrationProcess = new Thread(new ThreadStart(this.MigrationProcess));
00066                 migrationProcess.Start();
00067                 tbStatus.Focus();
00068             }
00069             else
00070             tbStatus.AppendText(errorString);
00071                 }
00072 
00073         private void UpdateStatusBox(string text)
00074         {
00075             tbStatus.AppendText(text);
00076             tbStatus.Refresh();
00077         }
00078 
00079         private void UpdateStatus(string text)
00080         {
00081             this.Invoke(new UpdateStatusDelegate(UpdateStatusBox), new object[] { text });
00082         }
00083 
00084         private void MigrationProcess()
00085         {
00086             string errorString = "";
00087             try
00088             {
00089                 UpdateStatus("Update process started...");
00090 
00091                 UpdateStatus("\r\nRAIS 3.1 to 3.2 DB update scripts started...");
00092                 ExecProcess(Application.StartupPath + @"\..\..\..\RAIS_DB\", "UpdateRais31ToRais32.cmd", sqlServerTextBox.Text + " " + sqlCatalogTextBox.Text);
00093                 UpdateStatus("\r\nRAIS 3.1 to 3.2 update scripts finished");
00094 
00095                 UpdateStatus("\r\nQuery table is being filled...");
00096                 string queriesFileName = Application.StartupPath + @"\..\..\..\RAIS_DB\RAIS32 Update Scripts\Rais32Queries.xml";
00097                 QueryTable.FillQueryTable(sqlConnection, queriesFileName);
00098                 UpdateStatus("\r\nQuery table has been filled.");
00099 
00100                 UpdateStatus("\r\n\r\nUpdate has been finished.");
00101 
00102             }
00103             catch (Exception ex)
00104             {
00105                 errorString = ex.Message;
00106                 if (ex is SqlException)
00107                 {
00108                     UpdateStatus("\r\nConnection to MS SQL Server failed...");
00109                 }
00110                 UpdateStatus("\r\n" + errorString);
00111                 UpdateStatus("\r\nUpdate process aborted with error");
00112             }
00113         }
00114 
00115        
00116                 private static int ExecProcess(string strWorkingDirectory, string strExePath, string strArguments)
00117                 {
00118                         Process prcStsadmin = new Process();
00119                         prcStsadmin.StartInfo.FileName = strExePath;
00120                         prcStsadmin.StartInfo.WorkingDirectory = strWorkingDirectory;
00121                         prcStsadmin.StartInfo.UseShellExecute = true;
00122                         prcStsadmin.StartInfo.RedirectStandardOutput = false;
00123                         prcStsadmin.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
00124                         prcStsadmin.StartInfo.Arguments = strArguments;
00125                         prcStsadmin.StartInfo.CreateNoWindow = false;
00126 
00127                         prcStsadmin.Start();
00128                         prcStsadmin.WaitForExit();
00129                         return prcStsadmin.ExitCode;
00130                 }
00131 
00132         private void cbIntegratedSecurity_CheckedChanged(object sender, EventArgs e)
00133         {
00134             loginTextBox.Enabled = !cbIntegratedSecurity.Checked;
00135             passTextBox.Enabled = !cbIntegratedSecurity.Checked;
00136             label5.Enabled = !cbIntegratedSecurity.Checked;
00137             label6.Enabled = !cbIntegratedSecurity.Checked;
00138         }
00139     }
00140 }